#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>


int main()
{
  int i = 0;
  pid_t arr[10];
  for(i = 0; i < 10; i++)
  {
    int id = fork();
    if (id == 0)
    {
      // child
      printf("child process created success! my pid is:%d\n", getpid());
      sleep(3);
      // child exit 
      exit(i); 
    }
    arr[i] = id;
  }


  // father
  for (i = 0; i < 10; i++ )
  {
    // use waitpid to get the child,s ret 
    int status = 0;
    pid_t ret = waitpid(arr[i],&status,0);
    if (ret >= 0)
    {
      printf("wait child process success! pid:%d\n",arr[i]);
      if (WIFEXITED(status))
      {
        // exit normal
        printf("exit code is:%d\n",WEXITSTATUS(status));
      }
      else{
        printf("killed by singin\n");
      }


    }
  }


  return 0;
}

